use std::env;
use std::process::Command;

fn main() {
    let version = match env::var("BUILD_VERSION") {
        Ok(version) => version,
        _ => Command::new("git")
            .args(["describe", "--tags"])
            .output()
            .map(|o| String::from_utf8(o.stdout).unwrap())
            .unwrap_or_else(|_| ">unknown<".to_string()),
    };

    println!("cargo:rustc-env=BUILD_VERSION={}", version);

    println!(
        "cargo:rustc-env=PROJ_WEB_DIR={}/web",
        env::var("CARGO_MANIFEST_DIR").unwrap()
    );

    built::write_built_file().expect("Failed to acquire build-time information");
}
